package com.dc.refactoring._6_处理概括关系._7_ExtractSuperclass.step2;

import com.google.common.collect.Lists;

import java.util.List;

/**
 * Description: 部门
 * @author: gdc
 * @date: 2020/12/13
 * @version 1.0
 */
public class Department extends Party {

    /**
     * 员工列表
     */
    private List<Employee> employees = Lists.newArrayList();

    public Department(String name) {
        super(name);
    }

    /**
     * 获取年度成本
     */
    //public Integer getTotalAnnualCost(){
    //    return getEmployees().stream().mapToInt(Employee::getAnnualCost).sum();
    //}

    // step 1 当前函数名称和 Employee 类中的 getAnnualCost() 用途相同，因此，修改方法名称，使其相同
    @Override
    public Integer getAnnualCost(){
        return getEmployees().stream().mapToInt(Employee::getAnnualCost).sum();
    }

    public List<Employee> getEmployees() {
        return employees;
    }

    /**
     * 添加员工
     */
    public void addEmployees(Employee employee) {
        employees.add(employee);
    }
}
